<template>
  <div class="app-container">
      <el-row>
  <el-col :span="22">
    
     <el-form ref="filterForm" :model="filterForm" :inline="true" label-position="left" label-width="100px">
        <el-form-item label="合约" prop="symbol">
          <el-input v-model="filterForm.symbol" clearable placeholder="合约" style="width: 200px;" class="filter-item" @keyup.enter.native="handleFilter" />
        </el-form-item>
        <el-form-item label="周期" prop="scale">
          
      <el-radio-group v-model="filterForm.scale">
        <el-radio-button label="0">全部</el-radio-button>
        <el-radio-button label="1">M1</el-radio-button>
        <el-radio-button label="3">M3</el-radio-button>
        <el-radio-button label="5">M5</el-radio-button>
        <el-radio-button label="10">M10</el-radio-button>
        <el-radio-button label="15">M15</el-radio-button>
        <el-radio-button label="30">M30</el-radio-button>
        <el-radio-button label="60">H1</el-radio-button>
        <el-radio-button label="120">H2</el-radio-button>
        <el-radio-button label="1440">D1</el-radio-button>
      </el-radio-group>
        </el-form-item>
        <el-form-item label="开仓状态" prop="openStatus">
          
      <el-radio-group v-model="filterForm.openStatus">
        <el-radio-button label="0">全部</el-radio-button>
        <el-radio-button label="1">未处理</el-radio-button>
        <el-radio-button label="2">已处理</el-radio-button>
      </el-radio-group>
        </el-form-item>
        <el-form-item label="平仓状态" prop="closeStatus">
          
      <el-radio-group v-model="filterForm.closeStatus">
        <el-radio-button label="0">全部</el-radio-button>
        <el-radio-button label="1">未处理</el-radio-button>
        <el-radio-button label="2">已处理</el-radio-button>
      </el-radio-group>
        </el-form-item>
      </el-form>
  </el-col>
  <el-col :span="2">
    <el-button type="primary" @click="handleFilter">搜索</el-button>
  </el-col>
</el-row>
      <el-row>
  <el-col :span="24">
      <el-table
      :data="signalList"
      border
      style="width: 100%">
      <el-table-column
        label="合约">
        <template slot-scope="{row}">
          <div>{{ row.symbol }}</div>
          <div>{{ row.signalID }}</div>
        </template>
      </el-table-column>
      <el-table-column
        prop="title"
        label="主题">
      </el-table-column>
      <el-table-column
        label="编码"
        width="100">
        <template slot-scope="{row}">
          <span>{{ row.magic }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="价格"
        width="100">
        <template slot-scope="{row}">
          <span>{{ row.marketPrice }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="开仓"
        width="100">
        <template slot-scope="{row}">
          <span v-if="row.openStatus == 1" style="color:red;">待处理</span>
          <span v-else style="color:green">已处理</span>
        </template>
      </el-table-column>
      <el-table-column
        label="平仓"
        width="100">
        <template slot-scope="{row}">
          <span v-if="row.closeStatus == 1" style="color:red;">待处理</span>
          <span v-else style="color:green">已处理</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="createdAt"
        label="创建时间"
        width="160">
      </el-table-column>
      </el-table>
  </el-col>
</el-row>
      
    
    <pagination v-show="total>0" :total="total" :page.sync="filterForm.page" :limit.sync="filterForm.size" @pagination="getSignalList" />

  </div>
</template>

<script>
//import { getFaultinessList,  removeFaultinessByID, changeFaultinessStatusByID } from '@/api/development/faultiness'
import waves from '@/directive/waves' // waves directive
import Pagination from '@/components/Pagination' // secondary package based on el-pagination
import {getHost} from '@/utils/socket' // secondary package based on el-pagination
import {getSymbol} from '@/utils/symbol' // secondary package based on el-pagination
import {getSignalList,subscribeSave,subscribeCannel,subscribeDelete} from '@/api/strategy/signal'
export default {
  name: 'faultinessAdmin',
  components: { Pagination },
  directives: { waves },
  filters: {
  },
  data() {
    return {
      
      socket:"",
      tableKey: 0,
      dataType:"1",
      windowHeight:"800",
      allowedLoaded:false,
      allowedLoadedRealtime:false,
      signalFilterForm:{},
      symbolList:[],
      policyList:[],
      signalList:[],
      purchaseList:[],
      contractList: [
      ],
      total: 0,
      listLoading: false,
      connected:"loading",
      realtimeSetting:{
        scale:1,
        symbol:"i2309"
      },
      positionForm:{
        localSymbol:"i",
        status:10,
        siminute:2
      },
      filterForm: {
        page: 1,
        size: 10,
        localSymbol:"I",
        openStatus:0,
        closeStatus:0,
        scale:1,
        symbol:''
      }
    }
  },
  created() {
    //开启行情自动读取
    this.allowedLoaded = true;
    this.allowedLoadedRealtime = true;
    let querySymbol = this.$route.query && this.$route.query.symbol
    if(querySymbol == undefined){
       querySymbol = window.localStorage.getItem("__local_symbol__")
    }
    if(querySymbol != undefined){
      this.filterForm.symbol = querySymbol
    }
    try {
      let symbolData = getSymbol()
      this.filterForm.localSymbol = symbolData.code
      this.positionForm.localSymbol = this.filterForm.localSymbol
      
    } catch (error) {
      
    }
    this.getSignalList()
  },
  mounted(){
  },
  destroyed(){
  },
  methods: {
    getSignalList:function(){
      let _this = this;
      console.log("期权",_this.filterForm)
      getSignalList(_this.filterForm).then((response) => {
        console.log("getSignalList",response)
          if (response.code === 200) {
            this.signalList = response.data.list
            this.total = response.data.total
          } else {
            _this.$message({
              message: response.msg,
              type: 'error'
            })
          }
      })
    },
    handleRefreshButton:function(){
        this.getList()
    },
    handleFilter() {
      console.log("合约变动")
      window.localStorage.setItem("__local_symbol__",this.filterForm.symbol)
      this.filterForm.page = 1
      this.allowedLoadedRealtime = true
      this.getSignalList()
    },
    sortChange(data) {
      const { prop, order } = data
      if (prop === 'id') {
        this.sortByID(order)
      }
    },
    sortByID(order) {
      if (order === 'ascending') {
        this.filterForm.sort = '+id'
      } else {
        this.filterForm.sort = '-id'
      }
      this.handleFilter()
    }
  }
}
</script>
<style>

</style>